home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume26 / bintools / part01 next >
Encoding:
Text File  |  1991-11-25  |  46.6 KB  |  1,665 lines

  1. Newsgroups: comp.sources.misc
  2. From: rthomson@dsd.es.com (Rich Thomson)
  3. Subject:  v26i073:  bintools - binary mail/post tools, Part01/01
  4. Message-ID: <1991Nov26.041835.2759@sparky.imd.sterling.com>
  5. X-Md4-Signature: 541cdf7f2531e20156ffcb17f70e2adc
  6. Date: Tue, 26 Nov 1991 04:18:35 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: rthomson@dsd.es.com (Rich Thomson)
  10. Posting-number: Volume 26, Issue 73
  11. Archive-name: bintools/part01
  12. Environment: UNIX
  13.  
  14. Now that trading binary files (i.e. images) has become quite popular
  15. on the net, I thought I would submit this.
  16.  
  17. These are a couple of tools I wrote to sanely post/mail binary
  18. files.  The files are uuencoded and split into pieces.  Each piece is
  19. packaged as a self-extracting shell archive.  Simple BEGIN/END
  20. markers delineating the end/beginning of header/footer material,
  21. respectively, are inserted for those without unshar capabilities.  
  22.  
  23. This gives a way of posting images that is backward compatible with
  24. the current convention (using BEGIN/END markers to delineate
  25. header/footers), while giving those with 'unshar' capabilities
  26. automatic decoding.  Further, decoding with the shell archive allows
  27. the pieces to be processed in any order.
  28.  
  29. This the first major revision of these scripts based on user feedback
  30. after an initial distribution on alt.sources.  New features of the
  31. 2.0 release of these scripts are:
  32.  
  33. Man pages
  34.     The first release was the scripts only.  Troff-source for man pages
  35.     is now included.
  36.  
  37. New flags:
  38.     -N count    Specify size of uuencoded chunks
  39.     -S sleep    Sleep between messages (useful for sluggish transport
  40.         systems)
  41.     -F file    Specify the name of the decoded file when processing
  42.         standard input.
  43.     -sysv
  44.     -bsd    Specify convention of your mail program
  45.  
  46. Improved shar header
  47.     Better instructions for decoding the shell archives is put into
  48.     the archive header prepended to each piece.  This includes
  49.     instructions for this without /bin/sh (or unix) capabilities.
  50.  
  51.                         -- Rich
  52.   ----
  53.     Repeal the personal income tax; vote Libertarian in 1992.
  54.         Disclaimer: I speak for myself, except as noted.
  55. UUCP: ...!uunet!dsd.es.com!rthomson            Rich Thomson
  56. Internet: rthomson@dsd.es.com    IRC: _Rich_        PEXt Programmer
  57. ----------
  58. #! /bin/sh
  59. # This is a shell archive.  Remove anything before this line, then feed it
  60. # into a shell via "sh file" or similar.  To overwrite existing files,
  61. # type "sh file -c".
  62. # The tool that generated this appeared in the comp.sources.unix newsgroup;
  63. # send mail to comp-sources-unix@uunet.uu.net if you want that tool.
  64. # Contents:  mail-bin mail-bin.1 post-bin post-bin.1 smail-bin
  65. # Wrapped by kent@sparky on Mon Nov 25 22:15:01 1991
  66. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  67. echo If this archive is complete, you will see the following message:
  68. echo '          "shar: End of archive 1 (of 1)."'
  69. if test -f 'mail-bin' -a "${1}" != "-c" ; then 
  70.   echo shar: Will not clobber existing file \"'mail-bin'\"
  71. else
  72.   echo shar: Extracting \"'mail-bin'\" \(11436 characters\)
  73.   sed "s/^X//" >'mail-bin' <<'END_OF_FILE'
  74. X#!/bin/sh
  75. X#
  76. X# mail-bin -- mail a binary file to someone
  77. X#
  78. X# $Header: mail-bin,v 2.1 91/11/24 19:31:38 rthomson Exp $
  79. X#
  80. X# mail-bin [options] address [file ...]
  81. X#
  82. X# Valid options are:
  83. X#
  84. X# -d descfile
  85. X#    Use the named file as the description of the image, to be placed
  86. X#    before each piece of the uuencoded file.  If no description file is
  87. X#    named, the user is placed into $EDITOR on a description file.  If
  88. X#    $EDITOR is undefined, vi is used.
  89. X#
  90. X# -t extra_text
  91. X#    Annotate the Subject: line with the extra text.
  92. X#
  93. X# -sysv
  94. X#    Use System V style mailer where Subject: line is the first line in
  95. X#    the body of the message instead of being specified with "-s"
  96. X# -bsd
  97. X#    Use BSD style mailer where Subject: line is given via "-s" switch.
  98. X#
  99. X# -N count
  100. X#    Split file into uuencoded pieces count lines long.
  101. X#
  102. X# -F filename
  103. X#    Decode to specified filename when reading from standard input.
  104. X#
  105. X# -S sleeptime
  106. X#    Sleep the specified number of seconds between messages.
  107. X#
  108. X# address
  109. X#    The mailing address of the person to receive the binary file.
  110. X#
  111. X# Mail-bin reads the named files, or the standard input if no files are
  112. X# named, and splits the files into 1000 line pieces.  Each piece is then
  113. X# mailed as a to the named recipient as a shell archive.  The sleep
  114. X# option is given because some mailers (notably, sendmail) can become
  115. X# overwhelmed with the number of mail messages that mail-bin can produce
  116. X# for large files.  By sleeping between messages (say 5 seconds per 1000
  117. X# lines) sent, mail-bin allows the mailer to catch up on processing then
  118. X# messages.
  119. X#
  120. X# If each shell archive is fed to the shell, the uuencoded pieces will
  121. X# be extracted from the archive and a rudimentary file length check will
  122. X# be performed on each piece.  Once all the pieces have been extracted,
  123. X# the pieces will be concatenated in their proper order and fed to
  124. X# uudecode.  If the uudecode operation is successful, the pieces will be
  125. X# removed.  Decoding may also be performed by concatenating the pieces
  126. X# (in the proper order) and feeding the result to the command:
  127. X#
  128. X#  sed -e '/^END/,/^BEGIN/d' | uudecode
  129. X#
  130. X# A description of the file, from the named description file or an
  131. X# editing session if none is named, is placed at the beginning of each
  132. X# message.
  133. X#
  134. X# Please send bugs/comments to rthomson@dsd.es.com
  135. X#
  136. X# Rich Thomson, June 28th, 1991
  137. X#
  138. X#       Copyright 1991 by Evans & Sutherland Computer Corporation,
  139. X#                  Salt Lake City, Utah
  140. X#
  141. X#                  All Rights Reserved
  142. X#
  143. X#     Permission to use, copy, modify, and distribute this software and its
  144. X#    documentation for any purpose and without fee is hereby granted,
  145. X#     provided that the above copyright notice appear in all copies and that
  146. X#    both that copyright notice and this permission notice appear in
  147. X#   supporting documentation, and that the names of Evans & Sutherland not be
  148. X#       used in advertising or publicity pertaining to distribution of the
  149. X#          software without specific, written prior permission.
  150. X#
  151. X#   EVANS & SUTHERLAND  DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  152. X#     INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  153. X#     EVENT SHALL EVANS & SUTHERLAND BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  154. X#  CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  155. X#     DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  156. X#    TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  157. X#             PERFORMANCE OF THIS SOFTWARE.
  158. X#
  159. X
  160. X# remove temporary files upon encountering interrupt or quit signal
  161. Xcleanup()
  162. X{
  163. X    rm -f /tmp/xx-$$-* /tmp/$$-description
  164. X    exit 1
  165. X}
  166. Xtrap cleanup 2 3
  167. X
  168. X# Stupid usage message
  169. Xusage()
  170. X{
  171. X    echo
  172. X    echo "Usage (revision $revision):"
  173. X    echo
  174. X    echo `basename $0` [options] address [file ...]
  175. X    echo
  176. X    echo Valid options are:
  177. X    echo
  178. X    echo "    [-help]          Get this help message"
  179. X    echo "    [-d descfile]    Specify prepared description file"
  180. X    echo "                     Default is to invoke the editor."
  181. X    echo "    [-t extra_text]  Annotate the subject line with extra text"
  182. X    echo "    [-N count]       Split file into uuencoded pieces of count lines"
  183. X    echo "                     Default: $count"
  184. X    echo "    [-F filename]    Decode to specified file when using stdin"
  185. X    echo "                     Default: $filename"
  186. X    echo "    [-S sleeptime]   Sleep sleeptime seconds between messages."
  187. X    echo "                     Default: $sleeptime"
  188. X    if [ $systemV = True ]; then
  189. X    echo "    [-sysv]          mail program is System V style (default)"
  190. X    echo "    [-bsd]           mail program is BSD style"    
  191. X    else
  192. X    echo "    [-sysv]          mail program is System V style"
  193. X    echo "    [-bsd]           mail program is BSD style (default)"
  194. X    fi
  195. X    if [ $verbosity = True ]; then
  196. X    echo "    [-v]             Operate verbosely (default)"
  197. X    echo "    [-q]             Operate quietly"
  198. X    else
  199. X    echo "    [-v]             Operate verbosely"
  200. X    echo "    [-q]             Operate quietly (default)"
  201. X    fi
  202. X    echo
  203. X    exit 1
  204. X}
  205. X
  206. X# print a message if the verbose flag is on.
  207. Xverbose()
  208. X{
  209. X    if [ $verbosity = True ]; then
  210. X    echo $*
  211. X    fi
  212. X}
  213. X
  214. X# This produces leading zeros for the part numbers.  NN users are
  215. X# anal-retentive about the subject lines being lexicographically ordered.
  216. Xzeros()
  217. X{
  218. X    case $1 in
  219. X    1 | 2 )
  220. X        echo $part
  221. X    ;;
  222. X    3 )
  223. X        echo 0$part | sed 's/^.*\(..\)$/\1/'
  224. X    ;;
  225. X    4 )
  226. X        echo 00$part | sed 's/^.*\(...\)$/\1/'
  227. X    ;;
  228. X    esac
  229. X}
  230. X
  231. X# put the header on the piece.  This includes a little /bin/sh preamble
  232. X# so that the file can be unpacked on the remote end with /bin/sh.
  233. X#
  234. Xheader()
  235. X{
  236. X    cat << _End_of_Header
  237. X#!/bin/sh
  238. X#
  239. X# This is a self-extracting shell archive of the binary file "$file".
  240. X# Created on `date` by `basename $0`, revision $revision.
  241. X#
  242. X# To decode with /bin/sh, remove everything before the /bin/sh and feed
  243. X# each piece as input to /bin/sh.  When all the pieces have been
  244. X# processed, the archive will automatically concatenate the pieces and
  245. X# uudecode them to produce $file.  If successful, it will remove all
  246. X# uuencoded pieces.  Alternatively, the archive(s) may be processed with
  247. X# no editing by the unshar program.
  248. X#
  249. X# If you do not have /bin/sh or unix, you may decode by removing
  250. X# everthing before/after the lines beginning with the word BEGIN/END,
  251. X# respectively, in each piece.  Then concatenate the pieces in the proper
  252. X# order and uudecode.
  253. X#
  254. Xpart=$print_part
  255. Xpfile=`echo $file | sed 's/^\(..........\).*$/\1/'`
  256. Xfile=$file
  257. Xpsize=`wc -c < $1 | sed 's/ //g'`
  258. Xsed -e '/^BEGIN/d' -e '/^END/d' << \End_of_Section > \$pfile.\$part
  259. XBEGIN------------ $file ------------ part $print_part/$num_parts ---
  260. X_End_of_Header
  261. X}
  262. X
  263. X# The /bin/sh trailer.  It does a rudimentary check on the length of
  264. X# the uuencoded piece extracted.  When all the pieces are present, it
  265. X# concatenates them into uudecode.  There is alot of creative shell
  266. X# quoting here.
  267. X#
  268. Xtrailer()
  269. X{
  270. X    echo END-------------- $file ------------ part $print_part/$num_parts ---
  271. X    cat << _End_of_Trailer
  272. XEnd_of_Section
  273. Xsize=\`wc -c \$pfile.\$part | awk '{ print \$1 }'\`
  274. Xif [ \$size != \$psize ]; then
  275. X    echo Length mismatch for uuencoded part \$part \(\$size != \$psize\).
  276. X    exit 1
  277. Xfi
  278. Xecho \$file, part \$part extracted.
  279. X
  280. Xif [ \`echo \$pfile.[0-9]* | wc -w\` = $num_parts ]; then
  281. X    echo All uuencoded parts of \$file extracted, uudecoding...
  282. X    cat \$pfile.* | uudecode
  283. X    if [ \$? -gt 0 ]; then
  284. X    echo Error encountered when uudecoding pieces...
  285. X    exit 1
  286. X    fi
  287. X
  288. X    echo \$file successfully uudecoded.  Removing uuencoded pieces.
  289. X    rm \$pfile.[0-9]*
  290. Xfi
  291. Xexit 0
  292. X_End_of_Trailer
  293. X}
  294. X
  295. X# Post each chunk of the file with appropriate header lines, description
  296. X# and header/footer pairs.
  297. Xmail_parts()
  298. X{
  299. X    file=$1
  300. X    shift
  301. X    num_parts=$#
  302. X    part=1
  303. X    num_zeros=`echo $num_parts | wc -c`
  304. X    while [ X$1 != X ]; do
  305. X    print_part=`zeros $num_zeros $part`
  306. X    verbose Mailing $file, part $print_part of $num_parts...
  307. X    if [ $systemV = True ]; then
  308. X        (echo To: $address; \
  309. X        echo Subject: $file, part $print_part/$num_parts $extra_text; \
  310. X        echo ''; \
  311. X        cat $descfile; \
  312. X        echo ''; \
  313. X        header $1; \
  314. X        cat $1; \
  315. X        trailer) \
  316. X        | mail $address
  317. X    else
  318. X        (cat $descfile; \
  319. X        echo ''; \
  320. X        header $1; \
  321. X        cat $1; \
  322. X        trailer) \
  323. X        | mail -s "$file, part $print_part/$num_parts $extra_text" $address
  324. X    fi
  325. X    part=`expr $part + 1`
  326. X    shift
  327. X    if [ X$1 != X ]; then
  328. X        sleep $sleeptime
  329. X    fi
  330. X    done
  331. X}
  332. X
  333. X# uuencode each file, splitting into $count line chunks.  Then mail each chunk.
  334. Xsplit_and_mail_files()
  335. X{
  336. X    while [ X$1 != X ]; do
  337. X    rm -f /tmp/xx-$$-*
  338. X    file=`basename $1`
  339. X    if [ $count -eq 0 ]; then
  340. X        verbose UUencoding $file...
  341. X        uuencode $1 $file > /tmp/xx-$$-aa
  342. X    else
  343. X        verbose UUencoding and splitting $file...
  344. X        uuencode $1 $file | split -$count - /tmp/xx-$$-
  345. X    fi
  346. X    mail_parts $file /tmp/xx-$$-*
  347. X    rm /tmp/xx-$$-*
  348. X    shift
  349. X    done
  350. X}
  351. X
  352. X# make sure we have descfile setup.  If it is not set, then invoke editor
  353. X# on temporary file
  354. Xget_desc_file()
  355. X{
  356. X    if [ X$descfile = X ]; then
  357. X    descfile=/tmp/$$-description
  358. X    touch $descfile
  359. X    $editor $descfile < /dev/tty
  360. X    fi
  361. X}
  362. X
  363. X# make sure description file created by get_desc_file is removed
  364. Xclean_desc_file()
  365. X{
  366. X    if [ $descfile = /tmp/$$-description ]; then
  367. X    rm $descfile
  368. X    fi
  369. X}
  370. X
  371. X# Check for blank or empty specification for required arguments.
  372. Xblank_arg()
  373. X{
  374. X    if [ "X$1" = X ]; then
  375. X    usage
  376. X    fi
  377. X}
  378. X
  379. X# initialize some variables
  380. X# No address by default; must be specified.
  381. Xaddress=""
  382. X# Invoke editor for description by default
  383. Xdescfile=""
  384. X# Default to stdin.
  385. Xfiles=""
  386. X# Decode into this file when using stdin.
  387. Xfilename="binary.data"
  388. X# No extra text by default
  389. Xextra_text=""
  390. X# Be verbose by default
  391. Xverbosity=True
  392. X# Use 1000 line chunks by default
  393. Xcount=1000
  394. X# Don't use System V style mailing by default
  395. XsystemV=False
  396. X# Don't sleep between parts by default
  397. Xsleeptime=0
  398. X# Revision of this script
  399. Xrevision=`echo $Revision: 2.1 $ | sed 's%[^0-9.]%%g'`
  400. Xif [ "X$EDITOR" = "X" ]; then
  401. X    editor=vi
  402. Xelse
  403. X    editor="$EDITOR"
  404. Xfi
  405. X
  406. X# parse the command line arguments
  407. Xwhile [ X$1 != X ]; do
  408. X    case $1 in
  409. X    -h* )
  410. X        usage
  411. X    ;;
  412. X
  413. X    -d* )
  414. X        descfile=$2;
  415. X        blank_arg $descfile
  416. X        shift
  417. X    ;;
  418. X
  419. X    -t* )
  420. X        extra_text="$2"
  421. X        shift
  422. X    ;;
  423. X
  424. X    -N* )
  425. X        count=$2
  426. X        blank_arg $count
  427. X        shift
  428. X    ;;
  429. X
  430. X    -sysv* )
  431. X        systemV=True
  432. X    ;;
  433. X
  434. X    -bsd* )
  435. X        systemV=False
  436. X    ;;
  437. X
  438. X    -F* )
  439. X        filename="$2"
  440. X        blank_arg $filename
  441. X        shift
  442. X    ;;
  443. X
  444. X    -S* )
  445. X        sleeptime="$2";
  446. X        blank_arg $sleeptime
  447. X        shift
  448. X    ;;
  449. X
  450. X    -q* )
  451. X        verbosity=False
  452. X    ;;
  453. X
  454. X    -v* )
  455. X        verbosity=True
  456. X    ;;
  457. X
  458. X    * )
  459. X        if [ "X$address" = X ]; then
  460. X        address=$1
  461. X        else
  462. X        if [ -r $1 ]; then
  463. X            if [ "X$files" = X ]; then
  464. X            files=$1
  465. X            else
  466. X            files="$files $1"
  467. X            fi
  468. X        else
  469. X            echo `basename $0`: can\'t read file $1.
  470. X            usage
  471. X        fi
  472. X        fi
  473. X    ;;
  474. X    esac
  475. X    shift
  476. Xdone
  477. X
  478. X# Must have a mail address before continuing
  479. Xif [ "X$address" = X ]; then
  480. X    echo Required address argument missing!
  481. X    echo
  482. X    usage
  483. Xfi
  484. X
  485. X# uuencode and split stdin, then mail; or split and mail file list
  486. Xif [ "X$files" = X ]; then
  487. X    if [ $count -eq 0 ]; then
  488. X    verbose UUencoding standard input as $filename...
  489. X    uuencode $filename > /tmp/xx-$$-aa
  490. X    else
  491. X    verbose UUencoding and splitting standard input as $filename...
  492. X    uuencode $filename | split -$count - /tmp/xx-$$-
  493. X    fi
  494. X    get_desc_file;
  495. X    mail_parts $filename /tmp/xx-$$-*;
  496. X    clean_desc_file;
  497. Xelse
  498. X    get_desc_file;
  499. X    split_and_mail_files $files;
  500. X    clean_desc_file;
  501. Xfi
  502. X
  503. Xexit 0
  504. END_OF_FILE
  505.   if test 11436 -ne `wc -c <'mail-bin'`; then
  506.     echo shar: \"'mail-bin'\" unpacked with wrong size!
  507.   fi
  508.   chmod +x 'mail-bin'
  509.   # end of 'mail-bin'
  510. fi
  511. if test -f 'mail-bin.1' -a "${1}" != "-c" ; then 
  512.   echo shar: Will not clobber existing file \"'mail-bin.1'\"
  513. else
  514.   echo shar: Extracting \"'mail-bin.1'\" \(5977 characters\)
  515.   sed "s/^X//" >'mail-bin.1' <<'END_OF_FILE'
  516. X.TH MAIL-BIN 1 "24 November 1991"
  517. X.\"
  518. X.\"       Copyright 1991 by Evans & Sutherland Computer Corporation,
  519. X.\"                  Salt Lake City, Utah
  520. X.\"
  521. X.\"                  All Rights Reserved
  522. X.\"
  523. X.\"   Permission to use, copy, modify, and distribute this software and its
  524. X.\"    documentation for any purpose and without fee is hereby granted,
  525. X.\"   provided that the above copyright notice appear in all copies and that
  526. X.\"    both that copyright notice and this permission notice appear in
  527. X.\" supporting documentation, and that the names of Evans & Sutherland not be
  528. X.\"     used in advertising or publicity pertaining to distribution of the
  529. X.\"          software without specific, written prior permission.
  530. X.\"
  531. X.\" EVANS & SUTHERLAND  DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  532. X.\"   INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  533. X.\"   EVENT SHALL EVANS & SUTHERLAND BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  534. X.\" CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  535. X.\"   DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  536. X.\"    TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  537. X.\"             PERFORMANCE OF THIS SOFTWARE.
  538. X.\"
  539. X.SH NAME
  540. Xmail-bin \- sanely mail a binary file to someone
  541. X.SH SYNOPSIS
  542. X.B mail-bin
  543. X[
  544. X.BI \-d\  descfile
  545. X]
  546. X[
  547. X.BI \-t\  extra_text
  548. X]
  549. X[
  550. X.B \-sysv
  551. X]
  552. X[
  553. X.B \-bsd
  554. X]
  555. X[
  556. X.BI \-N\  count
  557. X]
  558. X[
  559. X.BI \-F\  filename
  560. X]
  561. X[
  562. X.BI \-S\  sleeptime
  563. X]
  564. X[
  565. X.B \-v
  566. X]
  567. X[
  568. X.B \-q
  569. X]
  570. X[
  571. X.B \-help
  572. X]
  573. X.I address
  574. X[
  575. X.IR filename .\|.\|.
  576. X]
  577. X.LP
  578. X.SH DESCRIPTION
  579. X.LP
  580. X.B Mail-bin
  581. Xreads the named files, or the standard input if no files are named,
  582. Xuuencodes them, and splits the uuencoded files into pieces.
  583. XEach piece is then mailed as a to the named recipient as a self-extracting
  584. Xshell archive.
  585. X.LP
  586. XThe recipient then feeds the body of each message (the portion beginning
  587. Xat the #!/bin/sh line) as the standard input to /bin/sh.
  588. XIf the unshar program is available, it may be used to process each
  589. Xmessage without any editing.
  590. XThe received messages may be processed in any order (typically
  591. Xthey do not arrive in the order sent).  Once all pieces of a binary file
  592. Xhave been processed, the shell archive automatically concatenates the
  593. Xpieces in their proper order and uudecodes them.  If the file was
  594. Xsuccessfully uudecoded, the individual pieces are removed.
  595. X.LP
  596. XFor those without /bin/sh (or not running unix),
  597. Xdecoding may be performed by removing the all text before/after the
  598. Xlines beginning with the words BEGIN/END, respectively, in each
  599. Xpiece.  Then concatenate the pieces in the proper order and uudecode.
  600. X.LP
  601. XA description of the file, from the named description file or an
  602. Xediting session if none is named, is placed at the beginning of each
  603. Xmessage.
  604. X.LP
  605. XWhen sending large amounts of data, it is possible to overwhelm the
  606. Xlocal mail delivery system (most notably sendmail).  To accomodate for
  607. Xthis,
  608. X.B mail-bin
  609. Xprovides an option to sleep between messages to allow for a sluggish
  610. Xtransport system.
  611. X.SH OPTIONS
  612. X.TP
  613. X.BI \-d\  descfile
  614. XSpecifies a prepared description file.  Use /dev/null for no description.
  615. XIf
  616. X.B \-d
  617. Xis not specified, the user will be placed into the editor specified by the
  618. XEDITOR evironment variable.  If EDITOR is undefined, vi(1) will be used.
  619. X.TP
  620. X.BI \-t\  extra_text
  621. XAllows extra annotation text to be added to the subject line of each
  622. Xmessage generated.  Be sure to quote the text if it includes spaces.
  623. X.TP
  624. X.B \-sysv
  625. XThis option tells
  626. X.B mail-bin
  627. Xthat
  628. X.BR mail (1)
  629. Xis a System V style mail program that expects To: and Subject: lines
  630. Xon its standard input followed by a blank line and then the body of
  631. Xthe message.
  632. X.TP
  633. X.B \-bsd
  634. XThis option tells
  635. X.B mail-bin
  636. Xthat
  637. X.BR mail (1)
  638. Xis a BSD style mail program that expects the body of the message on
  639. Xits standard input with the subject of the message specified with the
  640. X-s option to
  641. X.BR mail (1).
  642. X.B Mail-bin
  643. Xassumes a BSD style mailer by default.
  644. X.TP
  645. X.BI \-N\  count
  646. XSpecifies the size, in lines, of the uuencoded pieces.  If the
  647. Xspecified count is zero, a single message containing the entire
  648. Xuuencoded file will be sent.  The default is 1000.
  649. X.TP
  650. X.BI \-F\  filename
  651. XWhen uuencoding the standard input, use the specified filename as the
  652. Xname the file should have when decoded.  The default is the name
  653. Xbinary.data.  This option is ignored when not processing the standard
  654. Xinput.
  655. X.TP
  656. X.BI \-S\  sleeptime
  657. XSleep for the given number of seconds between each message
  658. Xto allow for sluggish message transport systems (notably sendmail).
  659. X.TP
  660. X.B \-v
  661. XOperate verbosely, printing out progress of the uuencoding and mailing of
  662. Xthe piece.  This is the default.
  663. X.TP
  664. X.B \-q
  665. XOperate quietly.
  666. X.TP
  667. X.B \-help
  668. XPrint out a short summary of options.
  669. X.SH EXAMPLES
  670. X.LP
  671. XTo mail the binary file bark.jpeg to user baz@frobozz.com with the
  672. Xannotation subject line "JPEG file of tree bark" and no descriptive text in
  673. Xthe body of the message:
  674. X.IP
  675. Xmail-bin \-d /dev/null \-t 'JPEG file of tree bark' \\
  676. Xbaz@frobozz.com bark.jpeg
  677. X.LP
  678. XTo mail a compressed tar archive of the directory foo to user
  679. Xbaz@frobozz.com, sleeping 5 seconds between messages:
  680. X.IP
  681. Xtar cvf - foo | compress | mail-bin \-d /dev/null -F \\
  682. Xfoo.tar.Z -S 5 baz@frobozz.com
  683. X.SH ENVIRONMENT
  684. X.TP 20
  685. X.B EDITOR
  686. XThe name of the editor to use on the description file; defaults to vi.
  687. X.SH FILES
  688. X.TP 20
  689. X.B /tmp/xx-$$-
  690. XThe name of the split uuencoded pieces, appended with aa, ab, ac, etc.
  691. X$$ refers to the process id of the shell script.
  692. X.TP 20
  693. X.B /tmp/xx-$$-message
  694. XTemporary file for constructing the message body.
  695. X.TP 20
  696. X.B /tmp/$$-description
  697. XTemporary file used to contain the descriptive text.
  698. X.SH SEE ALSO
  699. X.BR post-bin (1),
  700. X.BR sh (1),
  701. X.BR uuencode (1),
  702. X.BR uudecode (1),
  703. X.BR split (1),
  704. X.BR unshar (1)
  705. X.SH AUTHOR
  706. XRich Thomson <rthomson@dsd.es.com>
  707. X.br
  708. XSoftware Engineer
  709. X.br
  710. XDesign Systems Division
  711. X.br
  712. XEvans & Sutherland Computer Corporation
  713. X.SH COPYRIGHT
  714. XCopyright (C) 1991, Evans & Sutherland Computer Corporation
  715. X.SH DIAGNOSTICS
  716. X.B Mail-bin
  717. Xwill complain about missing files and perform no action.
  718. X.SH BUGS
  719. XNone known.
  720. END_OF_FILE
  721.   if test 5977 -ne `wc -c <'mail-bin.1'`; then
  722.     echo shar: \"'mail-bin.1'\" unpacked with wrong size!
  723.   fi
  724.   # end of 'mail-bin.1'
  725. fi
  726. if test -f 'post-bin' -a "${1}" != "-c" ; then 
  727.   echo shar: Will not clobber existing file \"'post-bin'\"
  728. else
  729.   echo shar: Extracting \"'post-bin'\" \(11884 characters\)
  730.   sed "s/^X//" >'post-bin' <<'END_OF_FILE'
  731. X#!/bin/sh
  732. X#
  733. X# post-bin -- post a binary file to news
  734. X#
  735. X# $Header: post-bin,v 2.1 91/11/24 19:32:29 rthomson Exp $
  736. X#
  737. X# post-bin [options] [file...]
  738. X#
  739. X# Valid options are:
  740. X#
  741. X# -n newsgroup
  742. X#    Post the binary image to the named newsgroup.  If no newsgroup is
  743. X#    named, the default is alt.binaries.pictures.misc.
  744. X#
  745. X# -f follow-up
  746. X#    Set the "Followup-to:" field in the article to the named
  747. X#    newsgroup.  If none is specified, the default is
  748. X#    alt.binaries.pictures.d
  749. X#
  750. X# -D distribution
  751. X#    Set the "Distribution:" field in the articles to the named value.
  752. X#    The default distribution is world.
  753. X#
  754. X# -d descfile
  755. X#    Use the named file as the description of the image, to be placed
  756. X#    before each piece of the uuencoded file.  If no description file is
  757. X#    named, the user is placed into $EDITOR on a description file.  If
  758. X#    $EDITOR is undefined, vi is used.  Use '-d /dev/null' for no
  759. X#    description (not recommended!)
  760. X#
  761. X# -t extra_text
  762. X#    Add the supplied text to the end of the generated subject
  763. X#    strings.  This allows the articles' subjects to be annotated,
  764. X#    e.g. "[640x480, 256-color GIF]".
  765. X#
  766. X# -N count
  767. X#    Specify the size of the uuencoded pieces.  If count is zero, then
  768. X#    a single article will be posted (only recommended for small files).
  769. X#    Default: 1000
  770. X#
  771. X# -F filename
  772. X#    Decode to specified filename when reading from standard input.
  773. X#
  774. X# -S sleeptime
  775. X#    Sleep the specified number of seconds between articles.
  776. X#
  777. X# -v    Operate verbosely
  778. X# -q    Operate quietly
  779. X#
  780. X# Post-bin reads the named file(s), uuencodes them, and splits the files
  781. X# into pieces, usually 1000 lines or less in length.  Each piece is then
  782. X# posted as a news article containing a shell archive to the named
  783. X# newsgroup(s).  The sleep option is given because some transport
  784. X# mechanisms (notably, sendmail) can become overwhelmed with the number
  785. X# of articles that post-bin can produce for large files.  By sleeping
  786. X# between articles (say 5 seconds per 1000 lines) sent, post-bin allows
  787. X# the transport mechanism to catch up on processing the articles.
  788. X#
  789. X# If each shell archive is fed to the shell, the uuencoded pieces will
  790. X# be extracted from the archive and a rudimentary file lengthe check
  791. X# will be performed on each piece.  Once all the pieces have been
  792. X# extracted, the pieces will be concatenated in their proper order and
  793. X# fed to uudecode.  If the uudecode operation is successful, the pieces
  794. X# will be removed.
  795. X# 
  796. X# If you do not have /bin/sh or run unix, decoding may also be performed
  797. X# by concatenating the pieces (in the proper order) and feeding the result
  798. X# to the command:
  799. X#
  800. X#  sed -e '/^END/,/^BEGIN/d' | uudecode
  801. X#
  802. X# A description of the file, from the named description file or an
  803. X# editing session if none is named, is placed at the beginning of each
  804. X# article.
  805. X#
  806. X# Please send bugs/comments to rthomson@dsd.es.com
  807. X#
  808. X# Rich Thomson, June 3rd, 1991
  809. X#
  810. X#       Copyright 1991 by Evans & Sutherland Computer Corporation,
  811. X#                  Salt Lake City, Utah
  812. X#
  813. X#                  All Rights Reserved
  814. X#
  815. X#     Permission to use, copy, modify, and distribute this software and its
  816. X#    documentation for any purpose and without fee is hereby granted,
  817. X#     provided that the above copyright notice appear in all copies and that
  818. X#    both that copyright notice and this permission notice appear in
  819. X#   supporting documentation, and that the names of Evans & Sutherland not be
  820. X#       used in advertising or publicity pertaining to distribution of the
  821. X#          software without specific, written prior permission.
  822. X#
  823. X#   EVANS & SUTHERLAND  DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  824. X#     INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  825. X#     EVENT SHALL EVANS & SUTHERLAND BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  826. X#  CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  827. X#     DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  828. X#    TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  829. X#             PERFORMANCE OF THIS SOFTWARE.
  830. X#
  831. X
  832. X# remove temporary files upon encountering interrupt or quit signal
  833. Xcleanup()
  834. X{
  835. X    rm -f /tmp/xx-$$-* /tmp/$$-description
  836. X    exit 1
  837. X}
  838. Xtrap cleanup 2 3
  839. X
  840. X# Print a stupid usage message and exit with non-zero status.
  841. Xusage()
  842. X{
  843. X    echo
  844. X    echo "Usage (revision $revision):"
  845. X    echo
  846. X    echo "`basename $0` [options] [file ...]"
  847. X    echo
  848. X    echo Valid options are:
  849. X    echo
  850. X    echo "    [-help]           Get this help message"
  851. X    echo "    [-n newsgroup]    Specify destination newsgroup"
  852. X    echo "                      Default: $newsgroup"
  853. X    echo "    [-f followup-to]  Specify followup-to newsgroup"
  854. X    echo "                      Default: $followup"
  855. X    echo "    [-d descfile]     Specify prepared description file"
  856. X    echo "                      Default is to invoke the editor."
  857. X    echo "    [-D distribution] Specify distribution value"
  858. X    echo "                      Default: $dist"
  859. X    echo "    [-t extra text]   Annotate subject line with extra text"
  860. X    echo "    [-N count]        Split uuencoded file into count size chunks"
  861. X    echo "                      Default: $count"
  862. X    echo "    [-F filename]     Decode to specified file when using stdin"
  863. X    echo "                      Default: $filename"
  864. X    echo "    [-S sleeptime]    Sleep sleeptime seconds between articles."
  865. X    echo "                      Default: $sleeptime"
  866. X    if [ $verbosity = True ]; then
  867. X    echo "    [-v]              Operate verbosely (default)"
  868. X    echo "    [-q]              Operate quietly"
  869. X    else
  870. X    echo "    [-v]              Operate verbosely"
  871. X    echo "    [-q]              Operate quietly (default)"
  872. X    fi
  873. X    echo
  874. X
  875. X    exit 1
  876. X}
  877. X
  878. X# print a message if the verbose flag is on.
  879. Xverbose()
  880. X{
  881. X    if [ $verbosity = True ]; then
  882. X    echo $*
  883. X    fi
  884. X}
  885. X
  886. X# This produces leading zeros for the part numbers.  NN users are
  887. X# anal-retentive about the subject lines being lexicographically ordered.
  888. Xzeros()
  889. X{
  890. X    case $1 in
  891. X    1 | 2 )
  892. X        echo $part
  893. X    ;;
  894. X    3 )
  895. X        echo 0$part | sed 's/^.*\(..\)$/\1/'
  896. X    ;;
  897. X    4 )
  898. X        echo 00$part | sed 's/^.*\(...\)$/\1/'
  899. X    ;;
  900. X    5 )
  901. X        echo 000$part | sed 's/^.*\(....\)$/\1/'
  902. X    ;;
  903. X    esac
  904. X}
  905. X
  906. X# put the header on the piece.  This includes a little /bin/sh preamble
  907. X# so that the file can be unpacked on the remote end with /bin/sh.
  908. X#
  909. Xheader()
  910. X{
  911. X    cat << _End_of_Header
  912. X#!/bin/sh
  913. X#
  914. X# This is a self-extracting shell archive of the binary file "$file".
  915. X# Created on `date` by `basename $0`, revision $revision.
  916. X#
  917. X# To decode with /bin/sh, remove everything before the /bin/sh and feed
  918. X# each piece as input to /bin/sh.  When all the pieces have been
  919. X# processed, the archive will automatically concatenate the pieces and
  920. X# uudecode them to produce $file.  If successful, it will remove all
  921. X# uuencoded pieces.  Alternatively, the archive(s) may be processed with
  922. X# no editing by the unshar program.
  923. X#
  924. X# If you do not have /bin/sh or unix, you may decode by removing
  925. X# everthing before/after the lines beginning with the word BEGIN/END,
  926. X# respectively, in each piece.  Then concatenate the pieces in the proper
  927. X# order and uudecode.
  928. X#
  929. Xpart=$print_part
  930. Xpfile=`echo $file | sed 's/^\(..........\).*$/\1/'`
  931. Xfile=$file
  932. Xpsize=`wc -c < $1 | sed 's/ //g'`
  933. Xsed -e '/^BEGIN/d' -e '/^END/d' << \End_of_Section > \$pfile.\$part
  934. XBEGIN------------ $file ------------ part $print_part/$num_parts ---
  935. X_End_of_Header
  936. X}
  937. X
  938. X# The /bin/sh trailer.  It does a rudimentary check on the length of
  939. X# the uuencoded piece extracted.  When all the pieces are present, it
  940. X# concatenates them into uudecode.  There is alot of creative shell
  941. X# quoting here.
  942. X#
  943. Xtrailer()
  944. X{
  945. X    echo END-------------- $file ------------ part $print_part/$num_parts ---
  946. X    cat << _End_of_Trailer
  947. XEnd_of_Section
  948. Xsize=\`wc -c \$pfile.\$part | awk '{ print \$1 }'\`
  949. Xif [ \$size != \$psize ]; then
  950. X    echo Length mismatch for uuencoded part \$part \(\$size != \$psize\).
  951. X    exit 1
  952. Xfi
  953. Xecho \$file, part \$part extracted.
  954. X
  955. Xif [ \`echo \$pfile.[0-9]* | wc -w\` = $num_parts ]; then
  956. X    echo All uuencoded parts of \$file extracted, uudecoding...
  957. X    cat \$pfile.* | uudecode
  958. X    if [ \$? -gt 0 ]; then
  959. X    echo Error encountered when uudecoding pieces...
  960. X    exit 1
  961. X    fi
  962. X
  963. X    echo \$file successfully uudecoded.  Removing uuencoded pieces.
  964. X    rm \$pfile.[0-9]*
  965. Xfi
  966. Xexit 0
  967. X_End_of_Trailer
  968. X}
  969. X
  970. X# Post each chunk of the file with appropriate header lines, description
  971. X# and header/footer pairs.
  972. Xpost_parts()
  973. X{
  974. X    file=$1
  975. X    shift
  976. X    num_parts=$#
  977. X    part=1
  978. X    num_zeros=`echo $num_parts | wc -c`
  979. X    while [ X$1 != X ]; do
  980. X    print_part=`zeros $num_zeros $part`
  981. X    (echo Newsgroups: $newsgroup; \
  982. X    echo Subject: $file, part $print_part/$num_parts $extra_text; \
  983. X    echo Followup-to: $followup; \
  984. X    echo Distribution: $dist; \
  985. X    echo ''; \
  986. X    cat $descfile; \
  987. X    echo ''; \
  988. X    header $1; \
  989. X    cat $1; \
  990. X    trailer) \
  991. X    > /tmp/xx-$$-article
  992. X    verbose Posting $file, part $print_part of $num_parts...
  993. X    inews -h /tmp/xx-$$-article
  994. X    part=`expr $part + 1`
  995. X    shift
  996. X    if [ X$1 != X ]; then
  997. X        sleep $sleeptime
  998. X    fi
  999. X    done
  1000. X}
  1001. X
  1002. X# uuencode each file, splitting into $count line chunks.  Then post each chunk.
  1003. Xsplit_and_post_files()
  1004. X{
  1005. X    while [ X$1 != X ]; do
  1006. X    rm -f /tmp/xx-$$-*
  1007. X    file=`basename $1`
  1008. X    if [ $count -eq 0 ]; then
  1009. X        verbose UUencoding $file...
  1010. X        uuencode $1 $file > /tmp/xx-$$-aa
  1011. X    else
  1012. X        verbose UUencoding and splitting $file...
  1013. X        uuencode $1 $file | split -$count - /tmp/xx-$$-
  1014. X    fi
  1015. X    post_parts $file /tmp/xx-$$-*
  1016. X    rm /tmp/xx-$$-*
  1017. X    shift
  1018. X    done
  1019. X}
  1020. X
  1021. X# make sure we have descfile setup.  If it is not set, then invoke editor
  1022. X# on temporary file
  1023. Xget_desc_file()
  1024. X{
  1025. X    if [ X$descfile = X ]; then
  1026. X    descfile=/tmp/$$-description
  1027. X    touch $descfile
  1028. X    $editor $descfile < /dev/tty
  1029. X    fi
  1030. X}
  1031. X
  1032. X# make sure description file created by get_desc_file is removed
  1033. Xclean_desc_file()
  1034. X{
  1035. X    if [ $descfile = /tmp/$$-description ]; then
  1036. X    rm $descfile
  1037. X    fi
  1038. X}
  1039. X
  1040. X# Check for blank or empty specification for required arguments.
  1041. Xblank_arg()
  1042. X{
  1043. X    if [ "X$1" = X ]; then
  1044. X    usage
  1045. X    fi
  1046. X}
  1047. X
  1048. X# initialize some variables
  1049. X# Default newsgroup
  1050. Xnewsgroup="alt.binaries.pictures.misc"
  1051. X# Default followup newsgroup
  1052. Xfollowup="alt.binaries.pictures.d"
  1053. X# Default distribution
  1054. Xdist=world
  1055. X# Default description file (none; invoke editor)
  1056. Xdescfile=""
  1057. X# Default file list (none; use stdin)
  1058. Xfiles=""
  1059. X# Chunk size
  1060. Xcount=1000
  1061. X# Filename to use for uuencoding stdin
  1062. Xfilename="binary.data"
  1063. X# Initial extra text is empty
  1064. Xextra_text=""
  1065. X# Operate verbosely by default
  1066. Xverbosity=True
  1067. X# Don't sleep between parts by default
  1068. Xsleeptime=0
  1069. X# Revision of this script.
  1070. Xrevision=`echo $Revision: 2.1 $ | sed 's%[^0-9.]%%g'`
  1071. Xif [ "X$EDITOR" = "X" ]; then
  1072. X    editor=vi
  1073. Xelse
  1074. X    editor="$EDITOR"
  1075. Xfi
  1076. X
  1077. X# parse the command line arguments
  1078. Xwhile [ "X$1" != X ]; do
  1079. X    case $1 in
  1080. X    -h* )
  1081. X        usage
  1082. X    ;;
  1083. X
  1084. X    -t* )
  1085. X        extra_text="$2"
  1086. X        blank_arg $extra_text
  1087. X        shift
  1088. X    ;;
  1089. X
  1090. X    -n* )
  1091. X        newsgroup=$2
  1092. X        blank_arg $newsgroup
  1093. X        shift
  1094. X    ;;
  1095. X
  1096. X    -f* )
  1097. X        followup=$2
  1098. X        blank_arg $followup
  1099. X        shift
  1100. X    ;;
  1101. X
  1102. X    -D*)
  1103. X        dist=$2
  1104. X        blank_arg $dist
  1105. X        shift
  1106. X    ;;
  1107. X
  1108. X    -d* )
  1109. X        descfile=$2
  1110. X        blank_arg $descfile
  1111. X        shift
  1112. X    ;;
  1113. X
  1114. X    -N* )
  1115. X        count=$2
  1116. X        blank_arg $count
  1117. X        shift
  1118. X    ;;
  1119. X
  1120. X    -F* )
  1121. X        filename="$2"
  1122. X        blank_arg $filename
  1123. X        shift
  1124. X    ;;
  1125. X
  1126. X    -q* )
  1127. X        verbosity=False
  1128. X    ;;
  1129. X
  1130. X    -v* )
  1131. X        verbosity=True
  1132. X    ;;
  1133. X
  1134. X    * )
  1135. X        if [ -r $1 ]; then
  1136. X        if [ "X$files" = X ]; then
  1137. X            files=$1
  1138. X        else
  1139. X            files="$files $1"
  1140. X        fi
  1141. X        else
  1142. X        echo `basename $0`: can\'t read file $1.
  1143. X        usage
  1144. X        fi
  1145. X    ;;
  1146. X    esac
  1147. X    shift
  1148. Xdone
  1149. X
  1150. X# uuencode and split stdin, then post; or split and post file list
  1151. Xif [ "X$files" = X ]; then
  1152. X    if [ $count -eq 0 ]; then
  1153. X    verbose UUencoding standard input as $filename...
  1154. X    uuencode $filename > /tmp/xx-$$-aa
  1155. X    else
  1156. X        verbose UUencoding and splitting standard input as $filename...
  1157. X        uuencode $filename | split -$count - /tmp/xx-$$-
  1158. X    fi
  1159. X    get_desc_file
  1160. X    post_parts $filename /tmp/xx-$$-*
  1161. X    clean_desc_file
  1162. Xelse
  1163. X    get_desc_file
  1164. X    split_and_post_files $files
  1165. X    clean_desc_file
  1166. Xfi
  1167. X
  1168. Xexit 0
  1169. END_OF_FILE
  1170.   if test 11884 -ne `wc -c <'post-bin'`; then
  1171.     echo shar: \"'post-bin'\" unpacked with wrong size!
  1172.   fi
  1173.   chmod +x 'post-bin'
  1174.   # end of 'post-bin'
  1175. fi
  1176. if test -f 'post-bin.1' -a "${1}" != "-c" ; then 
  1177.   echo shar: Will not clobber existing file \"'post-bin.1'\"
  1178. else
  1179.   echo shar: Extracting \"'post-bin.1'\" \(5618 characters\)
  1180.   sed "s/^X//" >'post-bin.1' <<'END_OF_FILE'
  1181. X.TH POST-BIN 1 "24 November 1991"
  1182. X.\"
  1183. X.\"       Copyright 1991 by Evans & Sutherland Computer Corporation,
  1184. X.\"                  Salt Lake City, Utah
  1185. X.\"
  1186. X.\"                  All Rights Reserved
  1187. X.\"
  1188. X.\"   Permission to use, copy, modify, and distribute this software and its
  1189. X.\"    documentation for any purpose and without fee is hereby granted,
  1190. X.\"   provided that the above copyright notice appear in all copies and that
  1191. X.\"    both that copyright notice and this permission notice appear in
  1192. X.\" supporting documentation, and that the names of Evans & Sutherland not be
  1193. X.\"     used in advertising or publicity pertaining to distribution of the
  1194. X.\"          software without specific, written prior permission.
  1195. X.\"
  1196. X.\" EVANS & SUTHERLAND  DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  1197. X.\"   INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  1198. X.\"   EVENT SHALL EVANS & SUTHERLAND BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  1199. X.\" CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  1200. X.\"   DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  1201. X.\"   TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  1202. X.\"             PERFORMANCE OF THIS SOFTWARE.
  1203. X.\"
  1204. X.SH NAME
  1205. Xpost-bin \- sanely post a binary file to a newsgroup
  1206. X.SH SYNOPSIS
  1207. X.B post-bin
  1208. X[
  1209. X.BI \-n\  newsgroup
  1210. X]
  1211. X[
  1212. X.BI \-f\  follow-up
  1213. X]
  1214. X[
  1215. X.BI \-D\  distribution
  1216. X]
  1217. X[
  1218. X.BI \-d\  descfile
  1219. X]
  1220. X[
  1221. X.BI \-t\  extra_text
  1222. X]
  1223. X[
  1224. X.BI \-N\  count
  1225. X]
  1226. X[
  1227. X.BI \-F\  filename
  1228. X]
  1229. X[
  1230. X.BI \-S\  sleeptime
  1231. X]
  1232. X[
  1233. X.B \-v
  1234. X]
  1235. X[
  1236. X.B \-q
  1237. X]
  1238. X[
  1239. X.B \-help
  1240. X]
  1241. X[
  1242. X.IR filename .\|.\|.
  1243. X]
  1244. X.LP
  1245. X.SH DESCRIPTION
  1246. X.LP
  1247. X.B Post-bin
  1248. Xreads the named files, or the standard input if no files are named,
  1249. Xuuencodes them, and splits the uuencoded files into pieces.
  1250. XEach piece is then posted as to the named newsgroup as a self-extracting
  1251. Xshell archive.
  1252. X.LP
  1253. XThe reader then feeds the body of each article (the portion beginning
  1254. Xat the #!/bin/sh line) as the standard input to /bin/sh.
  1255. XIf the unshar program is available, it may be used to process each
  1256. Xarticle without any editing.  Some newsreaders (i.e. rn 4.4) also
  1257. Xprovide an "unshar" command that may also be used.
  1258. XThe received articles may be processed in any order (typically
  1259. Xthey do not arrive in the order sent).  Once all pieces of a binary file
  1260. Xhave been processed, the shell archive automatically concatenates the
  1261. Xpieces in their proper order and uudecodes them.  If the file was
  1262. Xsuccessfully uudecoded, the individual pieces are removed.
  1263. X.LP
  1264. XFor those readers without /bin/sh (or not running unix),
  1265. Xdecoding may be performed by removing the all text before/after the
  1266. Xlines beginning with the words BEGIN/END, respectively, in each
  1267. Xpiece.  Then concatenate the pieces in the proper order and uudecode.
  1268. X.LP
  1269. XA description of the file, from the named description file or an
  1270. Xediting session if none is named, is placed at the beginning of each
  1271. Xarticle.
  1272. X.SH OPTIONS
  1273. X.TP
  1274. X.BI \-n\  newsgroup
  1275. XPost the binary file to the named newsgroup.  Default:
  1276. Xalt.binaries.pictures.misc.
  1277. X.TP
  1278. X.BI \-f\  follow-up
  1279. XSet the Followup-To field in the header to the named newsgroup.  Default:
  1280. Xalt.binaries.pictures.d
  1281. X.TP
  1282. X.BI \-D\  distribution
  1283. XSet the Distribution field in the header to the named distribution.
  1284. XDefault: world
  1285. X.TP
  1286. X.BI \-d\  descfile
  1287. XSpecifies a prepared description file.  Use /dev/null for no description.
  1288. XIf
  1289. X.B \-d
  1290. Xis not specified, the user will be placed into the editor specified by the
  1291. XEDITOR evironment variable.  If EDITOR is undefined, vi(1) will be used.
  1292. X.TP
  1293. X.BI \-t\  extra_text
  1294. XAllows extra annotation text to be added to the subject line of each
  1295. Xarticle generated.  Be sure to quote the text if it includes spaces.
  1296. X.TP
  1297. X.BI \-N\  count
  1298. XSpecifies the size, in lines, of the uuencoded pieces.  If the
  1299. Xspecified count is zero, a single article containing the entire
  1300. Xuuencoded file will be sent.  The default is 1000.
  1301. X.TP
  1302. X.BI \-F\  filename
  1303. XWhen uuencoding the standard input, use the specified filename as the
  1304. Xname the file should have when decoded.  The default is the name
  1305. Xbinary.data.  This option is ignored when not processing the standard
  1306. Xinput.
  1307. X.TP
  1308. X.BI \-S\  sleeptime
  1309. XSleep for the given number of seconds between each each posted article
  1310. Xto allow for sluggish article transport systems.
  1311. X.TP
  1312. X.B \-v
  1313. XOperate verbosely, printing out progress of the uuencoding and posting of
  1314. Xthe piece.  This is the default.
  1315. X.TP
  1316. X.B \-q
  1317. XOperate quietly.
  1318. X.TP
  1319. X.B \-help
  1320. XPrint out a short summary of options.
  1321. X.SH EXAMPLES
  1322. X.LP
  1323. XWhen testing, it is often useful to post the image to a local newsgroup
  1324. Xwith a limited distribution.  In this example the description file is
  1325. Xgiven as /dev/null, which results in no descriptive text at the
  1326. Xbeginning of each article (not recommended for wide distribution):
  1327. X.IP
  1328. Xpost-bin \-D utah -n utah.test -f utah.test \-d \\
  1329. X/dev/null \-t 'JPEG file of tree bark' bark.jpeg
  1330. X.LP
  1331. X.SH ENVIRONMENT
  1332. X.TP 20
  1333. X.B EDITOR
  1334. XThe name of the editor to use on the description file; defaults to vi.
  1335. X.SH FILES
  1336. X.TP 20
  1337. X.B /tmp/xx-$$-
  1338. XThe name of the split uuencoded pieces, appended with aa, ab, ac, etc.
  1339. X$$ refers to the process id of the shell script.
  1340. X.TP 20
  1341. X.B /tmp/xx-$$-article
  1342. XTemporary file for constructing the article.
  1343. X.TP 20
  1344. X.B /tmp/$$-description
  1345. XTemporary file used to contain the descriptive text.
  1346. X.SH SEE ALSO
  1347. X.BR mail-bin (1),
  1348. X.BR sh (1),
  1349. X.BR uuencode (1),
  1350. X.BR uudecode (1),
  1351. X.BR split (1),
  1352. X.BR unshar (1)
  1353. X.SH AUTHOR
  1354. XRich Thomson <rthomson@dsd.es.com>
  1355. X.br
  1356. XSoftware Engineer
  1357. X.br
  1358. XDesign Systems Division
  1359. X.br
  1360. XEvans & Sutherland Computer Corporation
  1361. X.SH COPYRIGHT
  1362. XCopyright (C) 1991, Evans & Sutherland Computer Corporation
  1363. X.SH DIAGNOSTICS
  1364. X.B Post-bin
  1365. Xwill complain about missing files and perform no action.
  1366. X.SH BUGS
  1367. XNone known.
  1368. END_OF_FILE
  1369.   if test 5618 -ne `wc -c <'post-bin.1'`; then
  1370.     echo shar: \"'post-bin.1'\" unpacked with wrong size!
  1371.   fi
  1372.   # end of 'post-bin.1'
  1373. fi
  1374. if test -f 'smail-bin' -a "${1}" != "-c" ; then 
  1375.   echo shar: Will not clobber existing file \"'smail-bin'\"
  1376. else
  1377.   echo shar: Extracting \"'smail-bin'\" \(5916 characters\)
  1378.   sed "s/^X//" >'smail-bin' <<'END_OF_FILE'
  1379. X#!/bin/sh
  1380. X#
  1381. X# mail-bin -- mail a binary file to someone
  1382. X#
  1383. X# $Header: mail-bin,v 1.5 91/11/13 13:46:04 rthomson Exp $
  1384. X#
  1385. X# mail-bin [-d descfile] [-t extra_text] address [file ...]
  1386. X#
  1387. X# -d descfile
  1388. X#    Use the named file as the description of the image, to be placed
  1389. X#    before each piece of the uuencoded file.  If no description file is
  1390. X#    named, the user is placed into $EDITOR on a description file.  If
  1391. X#    $EDITOR is undefined, vi is used.
  1392. X#
  1393. X# -t extra_text
  1394. X#    Annotate the Subject: line with the extra text.
  1395. X#
  1396. X# address
  1397. X#    The mailing address of the person to receive the binary file.
  1398. X#
  1399. X# Mail-bin reads the named files, or the standard input if no files are named,
  1400. X# and splits the files into 1000 line pieces.  Each piece is then mailed as a
  1401. X# to the named recipient as a shell archive.  If each shell archive is
  1402. X# fed to the shell, the uuencoded pieces will be extracted from the
  1403. X# archive and a rudimentary file length check will be performed on each
  1404. X# piece.  Once all the pieces have been extracted, the pieces will be
  1405. X# concatenated in their proper order and fed to uudecode.  If the
  1406. X# uudecode operation is successful, the pieces will be removed.
  1407. X# Decoding may also be performed by concatenating the pieces (in the
  1408. X# proper order) and feeding the result to the command:
  1409. X#
  1410. X#  sed -e '/^END/,/^BEGIN/d' | uudecode
  1411. X#
  1412. X# A description of the file, from the named description file or an
  1413. X# editing session if none is named, is placed at the beginning of each
  1414. X# message.
  1415. X#
  1416. X# Please send bugs/comments to rthomson@dsd.es.com
  1417. X#
  1418. X# Rich Thomson, June 28th, 1991
  1419. X#
  1420. X
  1421. Xverbose()
  1422. X{
  1423. X    if [ $verbosity = True ]; then
  1424. X    echo $*
  1425. X    fi
  1426. X}
  1427. X
  1428. Xzeros()
  1429. X{
  1430. X    case $1 in
  1431. X    1 | 2 )
  1432. X        echo $part
  1433. X    ;;
  1434. X    3 )
  1435. X        echo 0$part | sed 's/^.*\(..\)$/\1/'
  1436. X    ;;
  1437. X    4 )
  1438. X        echo 00$part | sed 's/^.*\(...\)$/\1/'
  1439. X    ;;
  1440. X    esac
  1441. X}
  1442. X
  1443. X# put the header on the piece.  This includes a little /bin/sh preamble
  1444. X# so that the file can be unpacked on the remote end with /bin/sh.
  1445. X#
  1446. Xheader()
  1447. X{
  1448. X    cat << _End_of_Header
  1449. X#!/bin/sh
  1450. X#
  1451. X# This is a shell archive.  Cut everything off before the #!/bin/sh and
  1452. X# feed the rest of the file to /bin/sh.
  1453. X#
  1454. X#
  1455. Xpart=$print_part
  1456. Xfile=$file
  1457. Xpfile=`echo $file | sed 's/^\(..........\).*$/\1/'`
  1458. Xpsize=`wc -c < $1 | sed 's/ //g'`
  1459. Xsed -e '/^BEGIN/d' -e '/^END/d' << \End_of_Section > \$pfile.\$part
  1460. XBEGIN------------ $file ------------ part $print_part/$num_parts ---
  1461. X_End_of_Header
  1462. X}
  1463. X
  1464. Xtrailer()
  1465. X{
  1466. X    echo END-------------- $file ------------ part $print_part/$num_parts ---
  1467. X    cat << _End_of_Trailer
  1468. XEnd_of_Section
  1469. Xsize=\`wc -c \$pfile.\$part | awk '{ print \$1 }'\`
  1470. Xif [ \$size != \$psize ]; then
  1471. X    echo Length mismatch for uuencoded part \$part \(\$size != \$psize\).
  1472. X    exit 1
  1473. Xfi
  1474. Xecho \$file, part \$part extracted.
  1475. X
  1476. Xif [ \`echo \$pfile.[0-9]* | wc -w\` = $num_parts ]; then
  1477. X    echo All uuencoded parts of \$file extracted, uudecoding...
  1478. X    cat \$pfile.* | uudecode
  1479. X    if [ \$? -gt 0 ]; then
  1480. X    echo Error encountered when uudecoding pieces...
  1481. X    exit 1
  1482. X    fi
  1483. X
  1484. X    echo \$file successfully uudecoded.  Removing uuencoded pieces.
  1485. X    rm \$pfile.[0-9]*
  1486. Xfi
  1487. Xexit 0
  1488. X_End_of_Trailer
  1489. X}
  1490. X
  1491. X# Post each chunk of the file with appropriate header lines, description
  1492. X# and BEGIN/END pairs.
  1493. Xmail_parts()
  1494. X{
  1495. X    file=$1
  1496. X    shift
  1497. X    num_parts=$#
  1498. X    part=1
  1499. X    num_zeros=`echo $num_parts | wc -c`
  1500. X    while [ X$1 != X ]; do
  1501. X    print_part=`zeros $num_zeros $part`
  1502. X    (echo Subject: $file, part $print_part/$num_parts $extra_text ; \
  1503. X    cat $descfile; echo ''; header $1; cat $1; trailer) \
  1504. X        > /tmp/xx-$$-message
  1505. X    verbose Mailing $file, part $print_part of $num_parts...
  1506. X    mail $address < /tmp/xx-$$-message
  1507. X    part=`expr $part + 1`
  1508. X    shift
  1509. X    done
  1510. X}
  1511. X
  1512. X# uuencode each file, splitting into 1000 line chunks.  Then mail each chunk.
  1513. Xsplit_and_mail_files()
  1514. X{
  1515. X    while [ X$1 != X ]; do
  1516. X    rm -f /tmp/xx-$$-*
  1517. X    file=`basename $1`
  1518. X    verbose UUencoding and splitting $file...
  1519. X    uuencode $1 $file | split - /tmp/xx-$$-
  1520. X    mail_parts $file /tmp/xx-$$-*
  1521. X    rm /tmp/xx-$$-*
  1522. X    shift
  1523. X    done
  1524. X}
  1525. X
  1526. X# make sure we have descfile setup.  If it is not set, then invoke editor
  1527. X# on temporary file
  1528. Xget_desc_file()
  1529. X{
  1530. X    if [ X$descfile = X ]; then
  1531. X    descfile=/tmp/$$-description
  1532. X    touch $descfile
  1533. X    $editor $descfile
  1534. X    fi
  1535. X}
  1536. X
  1537. X# make sure description file created by get_desc_file is removed
  1538. Xclean_desc_file()
  1539. X{
  1540. X    if [ $descfile = /tmp/$$-description ]; then
  1541. X    rm $descfile
  1542. X    fi
  1543. X}
  1544. X
  1545. X# Stupid usage message
  1546. Xusage()
  1547. X{
  1548. X    echo Usage:
  1549. X    echo `basename $0` [-help] [-d descfile] [-v] address [file ...]
  1550. X    echo
  1551. X    echo "    [-help]          Get this help message"
  1552. X    echo "    [-d descfile]    Specify prepared description file"
  1553. X    echo "    [-t extra_text]  Annotate the subject line with extra text"
  1554. X    echo "    [-v]             Operate verbosely (default)"
  1555. X    echo "    [-q]             Operate quietly"
  1556. X    echo
  1557. X    exit 1
  1558. X}
  1559. X
  1560. X# initialize some variables
  1561. Xaddress=""
  1562. Xdescfile=""
  1563. Xfiles=""
  1564. Xextra_text=""
  1565. Xverbosity=True
  1566. Xif [ "X$EDITOR" = "X" ]; then
  1567. X    editor=vi
  1568. Xelse
  1569. X    editor="$EDITOR"
  1570. Xfi
  1571. X
  1572. X# parse the command line arguments
  1573. Xwhile [ X$1 != X ]; do
  1574. X    case $1 in
  1575. X    -h* )
  1576. X        usage
  1577. X    ;;
  1578. X
  1579. X    -d* )
  1580. X        descfile=$2;
  1581. X        if [ X$descfile = X ]; then
  1582. X        usage;
  1583. X        fi
  1584. X        shift
  1585. X    ;;
  1586. X
  1587. X    -t* )
  1588. X        extra_text="$2"
  1589. X        shift
  1590. X    ;;
  1591. X
  1592. X    -q* )
  1593. X        verbosity=False
  1594. X    ;;
  1595. X
  1596. X    -v* )
  1597. X        verbosity=True
  1598. X    ;;
  1599. X
  1600. X    * )
  1601. X        if [ "X$address" = X ]; then
  1602. X        address=$1
  1603. X        else
  1604. X        if [ "X$files" = X ]; then
  1605. X            files=$1
  1606. X        else
  1607. X            files="$files $1"
  1608. X        fi
  1609. X        fi
  1610. X    ;;
  1611. X    esac
  1612. X    shift
  1613. Xdone
  1614. X
  1615. X# Must have a mail address before continuing
  1616. Xif [ "X$address" = X ]; then
  1617. X    echo Required address argument missing!
  1618. X    echo
  1619. X    usage
  1620. Xfi
  1621. X
  1622. X# uuencode and split stdin, then mail; or split and mail file list
  1623. Xif [ "X$files" = X ]; then
  1624. X    verbose UUencoding and splitting standard input...
  1625. X    uuencode binary.data | split - /tmp/xx-$$-
  1626. X    get_desc_file;
  1627. X    mail_parts binary.data /tmp/xx-$$-*;
  1628. X    clean_desc_file;
  1629. Xelse
  1630. X    get_desc_file;
  1631. X    split_and_mail_files $files;
  1632. X    clean_desc_file;
  1633. Xfi
  1634. X
  1635. Xexit 0
  1636. END_OF_FILE
  1637.   if test 5916 -ne `wc -c <'smail-bin'`; then
  1638.     echo shar: \"'smail-bin'\" unpacked with wrong size!
  1639.   fi
  1640.   chmod +x 'smail-bin'
  1641.   # end of 'smail-bin'
  1642. fi
  1643. echo shar: End of archive 1 \(of 1\).
  1644. cp /dev/null ark1isdone
  1645. MISSING=""
  1646. for I in 1 ; do
  1647.     if test ! -f ark${I}isdone ; then
  1648.     MISSING="${MISSING} ${I}"
  1649.     fi
  1650. done
  1651. if test "${MISSING}" = "" ; then
  1652.     echo You have the archive.
  1653.     rm -f ark[1-9]isdone
  1654. else
  1655.     echo You still must unpack the following archives:
  1656.     echo "        " ${MISSING}
  1657. fi
  1658. exit 0
  1659. exit 0 # Just in case...
  1660. -- 
  1661. Kent Landfield                   INTERNET: kent@sparky.IMD.Sterling.COM
  1662. Sterling Software, IMD           UUCP:     uunet!sparky!kent
  1663. Phone:    (402) 291-8300         FAX:      (402) 291-4362
  1664. Please send comp.sources.misc-related mail to kent@uunet.uu.net.
  1665.